# encoding    : utf-8 -*-                            
# @author     :
# @file       :   appium_app.py
# @Time       :   2025/1/2 10:49
from appium import webdriver
from appium.options.common import AppiumOptions
from selenium.webdriver.support import expected_conditions as EC
# from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.appiumby import AppiumBy
# from appium.webdriver.common.touch_action import TouchAction   #坐标,2.0版本级以上的appium已经弃用，不能使用
import time

from selenium.webdriver.support.wait import WebDriverWait


caps = {
  "appActivity": ".SplashActivity",
  "platformName": "Android",
  "platformVersion": "12",
  "deviceName": "127.0.0.1:7555",
  "appPackage": "com.sina.weibo",
  "automationName":'UiAutomator2'
}

url = "http://127.0.0.1:4723"
options = AppiumOptions().load_capabilities(caps)
driver = webdriver.Remote(url,options=options)
time.sleep(10)


#点击同意并继续
driver.find_element(AppiumBy.XPATH, '//android.widget.TextView[@text="同意并继续"]').click()
time.sleep(5)

#点击发现按钮
ele = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
            (AppiumBy.XPATH, '(//android.widget.FrameLayout[@content-desc="发现"])[13]')))
ele.click()
time.sleep(5)

# #点击我知道了
# driver.find_element(AppiumBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.ImageView").click()
# time.sleep(5)

#点击输入框
driver.tap([(460, 73)], 100)
time.sleep(5)

#输入8848
driver.find_element(AppiumBy.ID,"com.sina.weibo:id/tv_search_keyword").send_keys("8848")
time.sleep(5)


#模拟键盘按下enter键
driver.press_keycode(66)
time.sleep(5)


for i in range(10):
    # TouchAction(driver).press(x = 1,y = 1).move_to(x = 1,y =5 ).release().perform()
    driver.swipe(start_x=400,start_y=1200,end_x=400,end_y=300,duration=400)
    # time.sleep(3)
    
    
driver.quit()


